<template>
    <div class="run">
        <DashHeader/>
        <el-main>
  
  <el-form ref="form" :model="form" label-width="120px">
    <h4>
        选择测试参数
    </h4>
    <el-form-item label="测试产品">
      <el-select v-model="form.product" placeholder="select your product">
        <el-option label="EVI" value="evicloud">EVI</el-option>
        <el-option label="数字矿山" value="ddm">数字矿山</el-option>
      </el-select>
    </el-form-item>
        <el-form-item label="测试类型">
      <el-select v-model="form.type" placeholder="select your type">
        <el-option label="功能测试" value="function">功能测试</el-option>
        <el-option label="性能测试" value="performance">性能测试</el-option>
      </el-select>
    </el-form-item>
     <el-form-item v-if="form.type==='function'" label="执行环境">
      <el-select v-model="form.env"  placeholder="select your environment">
        <el-option label="测试环境" value="test">测试环境</el-option>
        <el-option label="集成环境" value="instrg">集成环境</el-option>
      </el-select>
    </el-form-item>
         <el-form-item v-if="form.type==='function'" label="用例优先级">
       <el-select v-model="form.serverity" multiple placeholder="Select">
    <el-option
      v-for="item in s_options"
      :key="item"
      :label="item"
      :value="item"
    >
    </el-option>
      </el-select>
    </el-form-item>
    <el-form-item v-if="form.type==='function'" label="测试微服务">
     <el-select v-model="form.modules" multiple placeholder="Select">
    <el-option
      v-for="item in ms_options"
      :key="item"
      :label="item"
      :value="item"
    >
    </el-option>
  </el-select>
    </el-form-item>  
         <el-form-item v-if="form.type==='performance'" label="测试接口">     
        <el-select v-model="form.interfaces" multiple placeholder="Select">
    <el-option
      v-for="item in interfaces_options"
      :key="item"
      :label="item"
      :value="item"
    >
    </el-option>
      </el-select>
    </el-form-item> 

    <el-form-item label="通知邮箱">
      <el-input v-model="form.email" style="width:300px" type="textarea"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">执行测试</el-button>
    </el-form-item>
  </el-form>


  </el-main>
    </div>

</template>
<script>
import  DashHeader from '@/components/DashHeader'
export default {
     name: 'Run',
   components: {
       DashHeader
   },
  data() {
    return {
        ms_options:['evi_portal_device',
        'evi_portal_web','evi_portal_generatefile','evi_rule_engine',
        'evi_portal_mapi','evi_portal_extend','evi_portal_alarm','evi_portal_srvops',
        'evi_portal_rice','evi_portal_opdata','evi_portal_bi','evi_portal_credit',
        'evi_portal_monitor','log_cloud','emqx_ee','gateway_server'          
        ],
        interfaces_options:['aff4d321-7cc8-4ceb-8665-9f9241e61793'           
        ],
        s_options:['critical','normal','minor'],
        planid: '',
      form: {
        product: 'evicloud',
        env: 'test',
        type: 'function',
        serverity: ['critical','normal','minor'],
        modules: ['evi_portal_web'],  
        interfaces: ['aff4d321-7cc8-4ceb-8665-9f9241e61793'],      
        email: ''
      },
    }
  },
  methods: {
    async onSubmit() {
      if (this.form.type === 'function') {
      var url = "/api/v1/operation/planjenkins";
           await this.$http.post(url,{            
                    'project':this.form.product,
                    'runningEnv':this.form.env,
                    'modules':this.form.modules,
                    'caseServerity': this.form.serverity,
                    'mailReceiver': this.form.email
                     })
                     .then(resp => {
               window.console.log(resp.data)
               this.planid = resp.data
           })
      } else {      
      var urlp = "/api/v1/operation/performance";
           await this.$http.post(urlp,{            
                    'id':this.form.interfaces[0],                   
                     })
                     .then(resp => {
               window.console.log(resp.data)
               this.planid = resp.data
           })
      }
            
           //提示执行成功
           var message =  '测试ID为：' + this.planid
           this.$alert(message, '测试开始执行', {
          confirmButtonText: '确定',
            callback: () => {
            this.$message({
              type: 'info',
              message: `开始测试`,
            })
          }, 
        })
        
       }
  },
}
</script>